<template>
  <el-dialog
    :title="title"
    :visible.sync="addDialogVisible"
    :close-on-click-modal="false"
    v-if="addDialogVisible"
    width="30%"
    :before-close="handleClose"
  >
    <div>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="节点名称" prop="name">
          <el-input
            v-model="ruleForm.name"
            @keyup.enter.native="submitForm('ruleForm')"
            v-focus
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span class="dialog-footer">
      <el-button @click="resetForm('ruleForm')">取 消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: ["addDialogVisible","title"],
  components: {},
  data() {
    return {
      ruleForm: {
        name: "",
      },
      rules: {
        name: [{ required: true, message: "请输入节点", trigger: "blur" }],
      },
    };
  },
  methods: {
    handleClose() {
      this.resetForm("ruleForm");
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit("saveNodes", this.ruleForm.name);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.ruleForm = {
        name: "",
      };
      this.$refs[formName].resetFields();
      this.$emit("close");
    },
    clearForm(formName) {
        this.ruleForm = {
        name: "",
      };
      this.$refs[formName].resetFields();
    }
  },
  created() {},
};
</script>
<style lang="scss" scoped>
.dialog-footer {
  display: flex;
  justify-content: center;
}

.addbtn{
  margin-left: 10px;
  height: 30px;
}
</style>
